﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace MvcEngine.Core.Configuration
{
    public class ExtensionConfigurationCollection : ConfigurationElementCollection
    {
        public ExtensionConfigurationElement this[int index]
        {
            get
            {
                return base.BaseGet(index) as ExtensionConfigurationElement;
            }
            set
            {
                if (base.BaseGet(index) != null)
                {
                    base.BaseRemoveAt(index);
                }
                this.BaseAdd(index, value);
            }
        }

        public new string this[string name]
        {
            get
            {
                for (int i = 0; i < this.Count; i++)
                {
                    if (this[i].Name == name)
                        return this[i].Type;
                }
                return null;
            }
        }

        public ExtensionConfigurationElement GetElement(string extension) 
        {
            for (int i = 0; i < this.Count; i++)
            {
                if (this[i].Name == extension)
                    return this[i];
            }
            return null;
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new ExtensionConfigurationElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ExtensionConfigurationElement)element).Name;
        }
    }
}
